<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<style>
    /* css3动画
        animation-name
        animation-duration
        animation-timing-function
        animation-delay
        animation-iteration-count
        anitmation-direction
    */
    @keyframes play {

        /* to {
            width: 100%
        } */
        0% {
            transform: translateX(-50%) scaleX(0);
        }

        to {
            transform: translateX(0) scaleX(1);
        }
    }

    @keyframes replay {
        /* to {
            width: 100%
        } */
        0% {
            /* 从中间开始缩放，translateX是为了从头部开始缩放 */
            transform: translateX(-50%) scaleX(0);
        }

        to {
            transform: translateX(0) scaleX(1);
        }
    }

    .container {
        height: 10px;
        border-radius: 5px;
        border: 1px solid;
    }

    .progress {
        height: 100%;
        /* width: 0; */
        width: 100%;
        will-change: transform;
        background: red;
        animation-timing-function: linear;
    }

    .progress.play {
        animation-play-state: running;
    }

    .progress.pause {
        animation-play-state: paused;
    }
</style>

<body>
    <div id="app">
        <button @click="handleVideo">{{isPlay?"暂停":"播放"}}</button>
        <button @click="replay">重播</button>
        <span>{{'播放次数为:'+count}}</span>
        <div class="container">
            <div :class="['progress', isPlay?'play':'pause']" :style="{animationDuration: `${totalTime}ms`,animationName: `${type?'replay':'play'}`}"
                @animationEnd="end"></div>
        </div>
    </div>                                                                                   

</body>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            isPlay: false,
            count: 0,
            type: 0,
            totalTime: 3000
        },
        methods: {
            handleVideo: function () {
                this.isPlay = !this.isPlay
            },
            replay: function () {
                this.isPlay = true
                this.type ? this.type = 0 : this.type = 1
            },
            end: function () {
                console.log("end")
                this.count += 1
                this.replay()
            }
        }
    })
    console.log([...new Set([1,1,1,2,3,3,4,5,6])])
</script>


</html>